<template>
  <view class="u-wrap">
    <view class="u-menu-wrap">
      <scroll-view scroll-y scroll-with-animation class="u-tab-view" :scroll-top="scrollTop"
                   :scroll-into-view="itemId">
        <view v-for="(item,index) in labelList" :key="index" class="u-tab-item"
              :class="[current == index ? 'u-tab-item-active' : '']"
              @click.stop="swichMenu(index, item)">
          <text class="u-line-1">{{item}}</text>
        </view>
      </scroll-view>
      <scroll-view scroll-y scroll-with-animation class="page-view" :scroll-top="scrollTop"
                   :scroll-into-view="itemId">
        <view v-for="(item,index) in labelChildList" :key="index" class="u-tab-child-item"
              :class="[currentChild == index ? 'u-tab-item-active' : '']"
              @click.stop="swichChildMenu(index, item)">
          <text class="u-line-1">{{item}}</text>
        </view>
      </scroll-view>
    </view>
  </view>
</template>
<script setup>
import {ref, computed, onMounted} from 'vue'
import {useTagLibraryStore} from '@/store'

const current = ref(0)
const currentChild = ref(0)
const tagLibraryStore = useTagLibraryStore()
onMounted(async () => {
  await tagLibraryStore.articleList()
  await tagLibraryStore.articleAllList()
  swichMenu(current.value, Object.keys(tagLibraryStore?.contentTagList?.articleAllList)[current.value])
})
const labelList = computed(() => {
  return Object.keys(tagLibraryStore?.contentTagList?.articleAllList)
})

const labelChildList = ref(null)

const swichMenu = (index, tagName) => {
  current.value = index;
  labelChildList.value = tagLibraryStore?.contentTagList?.articleAllList[tagName].map((label) => {
    return label.tagLibraryBO.tagName
  })
  swichChildMenu(currentChild.value)
}

const swichChildMenu = (index) => {
  currentChild.value = index;
}
</script>

<style lang="scss" scoped>
.u-wrap {
  height: calc(100vh);
  /* #ifdef H5 */
  height: calc(100vh - var(--window-top));
  /* #endif */
  display: flex;
  flex-direction: column;
}

.u-menu-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.u-tab-view {
  width: 200rpx;
  height: 100%;
}

.u-tab-item {
  height: 110rpx;
  background: #f6f6f6;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26rpx;
  color: #444;
  font-weight: 400;
  line-height: 1;
}

.u-tab-child-item {
  height: 110rpx;
  background: #f6f6f6;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26rpx;
  color: #444;
  font-weight: 400;
  line-height: 1;
}

.u-tab-item-active {
  position: relative;
  color: #FE5C71;
  font-size: 30rpx;
  font-weight: 600;
  background: #fff;
}

.u-tab-item-active::before {
  content: "";
  position: absolute;
  border-left: 4px solid $u-primary;
  height: 32rpx;
  left: 0;
  top: 39rpx;
}

.u-class-item-active {
  position: relative;
  color: #000;
  font-size: 30rpx;
  font-weight: 600;
  background: #fff;
}

.u-class-item-active::before {
  content: "";
  position: absolute;
  border-left: 4px solid $u-primary;
  height: 32rpx;
  left: 0;
  top: 39rpx;
}

.u-tab-view {
  height: 100%;
  background: #f6f6f6;
  border-right: 2px solid #b2b2b2;
}

.page-view {
  height: 100%;
  padding: 16rpx;
  background: #f8f8f8;
}

.item-title {
  font-size: 26rpx;
  color: $u-main-color;
  font-weight: bold;
}
</style>